<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .img {
            list-style: none;
            width: 590px;
            height: 470px;
            position: absolute;
            transition: 0.7s;
            opacity: 0;
        }

        .img-box {
            margin: 0px;
            padding: 0px;
            position: relative;
            height: 470px;
            width: 590px;
        }

        button {
            position: absolute;
            height: 100px;
            width: 40px;
            background-color: rgba(0, 0, 0, 0.5);
            color: white;
            top: 50%;
            transform: translateY(-50%);
            border: none;
            z-index: 100;
            /* opacity: 0.5; */
        }

        .left {
            border-radius: 0px 20px 20px 0px;
        }

        .right {
            border-radius: 20px 0px 0px 20px;
            right: 0px;
        }

        .point-box {
            position: absolute;
            list-style: none;
            padding: 0px;
            margin: 0px;
            display: flex;
            width: 100px;
            justify-content: space-between;
            bottom: 20px;
            left: 20px;
        }

        .point {
            height: 10px;
            width: 10px;
            border-radius: 50%;
            background-color: black;
            color: rgba(0, 0, 0, 0)
        }

        .active {
            /* z-index: 10; */
            opacity: 1;
        }

        .pointActive {
            background-color: white;
        }
    </style>
</head>

<body>
    <ul class="img-box">
        <li class="img active">
            <img src="./1.jpg" alt="">
        </li>
        <li class="img">
            <img src="./2.jpg" alt="">
        </li>
        <li class="img">
            <img src="./3.jpg" alt="">
        </li>
        <li class="img">
            <img src="./4.jpg" alt="">
        </li>
        <li class="img">
            <img src="./5.jpg" alt="">
        </li>

        <li class="img">
            <img src="./6.jpg" alt="">
        </li>
        <button class="left" type="button">
            < </button>
                <button type="button" class="right"> > </button>
                <ul class="point-box">
                    <li class="point pointActive">1</li>
                    <li class="point">2</li>
                    <li class="point">3</li>
                    <li class="point">4</li>
                    <li class="point">5</li>
                    <li class="point">6</li>
                </ul>
    </ul>
    <script>
        var left = document.querySelector('.left')
        var right = document.querySelector('.right')
        var imgs = document.querySelectorAll('.img')
        var points = document.querySelectorAll('.point')
        var index = 0 //代指img所在的li的下标
        right.addEventListener('click', function () {
            imgs[index].classList.remove('active')
            points[index].classList.remove('pointActive')
            index++;
            if (index >= 6) {
                index = 0
            }
            imgs[index].classList.add('active')
            points[index].classList.add('pointActive')
        })
        left.addEventListener('click', function () {
            imgs[index].classList.remove('active')
            points[index].classList.remove('pointActive')
            index--;
            if (index <= -1) {
                index = 5
            }
            imgs[index].classList.add('active')
            points[index].classList.add('pointActive')
        })

        points.forEach(function (item) {
            item.addEventListener('mousemove', function () {
                imgs[index].classList.remove('active')
                points[index].classList.remove('pointActive')
                index = this.innerText - 1
                imgs[index].classList.add('active')
                points[index].classList.add('pointActive')
            })
        })

        setInterval(function () {
            imgs[index].classList.remove('active')
            points[index].classList.remove('pointActive')
            index++;
            if (index >= 6) {
                index = 0
            }
            imgs[index].classList.add('active')
            points[index].classList.add('pointActive')
        }, 2000);
    </script>

</body>

</html>